home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 2.8 KB | 169 lines | [TEXT/SPM ] |
- #include <Traps.h>
- #include "SAGlobals.h"
- #include "Drawing.h"
- #include "PPCXfer.h"
- #include <Gestalt.h>
-
- QDGlobals qd;
-
- typedef pascal void (*DrawPictPP)(PicHandle, Rect*);
- typedef pascal Handle (*GetPictPP)(short);
- typedef pascal void (*InitWindPP)(void);
- typedef pascal void (*InitPPC_PP)(PPCXfer*);
-
- GetPictPP oldGetPicture;
- DrawPictPP oldDrawPicture;
- InitWindPP oldInitWindows;
- Ptr oldLaunch;
- Boolean doCleanup;
- Boolean bypass;
- Boolean isRunning;
-
- extern "C" {
- pascal Handle MyGetPicture(short);
- pascal void MyDrawPicture(PicHandle, Rect*);
- pascal void MyInitWindows(void);
- //extern void MyLaunch(void);
- }
-
- pascal void SETGLOB(void);
- pascal void RESETGLOB(void);
-
- Str31 extFileName;
- short extVRefNum;
- long extDirID;
-
- extern "C" void main(void)
- {
- Handle me;
- PPCXfer ppcx;
-
- if (InitA5())
- {
- SETGLOB();
-
- doCleanup = false;
- bypass = false;
- isRunning = false;
-
- {
- FCBPBRec pb;
-
- pb.ioFCBIndx = 0;
- pb.ioVRefNum = 0;
- pb.ioRefNum = CurResFile();
- pb.ioNamePtr = extFileName;
- PBGetFCBInfoSync(&pb);
-
- extVRefNum = pb.ioFCBVRefNum;
- extDirID = pb.ioFCBParID;
- }
-
- oldGetPicture = (GetPictPP) GetToolTrapAddress(_GetPicture);
- SetToolTrapAddress((UniversalProcPtr) MyGetPicture, _GetPicture);
-
- RESETGLOB();
- }
- }
-
- pascal Handle MyGetPicture(short id)
- {
- GetPictPP gp;
-
- SETGLOB();
- gp = oldGetPicture;
-
- if (!bypass && !isRunning)
- {
- short cResFile = CurResFile();
- short myFile;
-
- myFile = HOpenResFile(extVRefNum, extDirID, extFileName, fsCurPerm);
- UseResFile(myFile);
- if (InitDraw(id))
- bypass = true;
- CloseResFile(myFile);
- UseResFile(cResFile);
-
- if (!bypass)
- {
- oldDrawPicture = (DrawPictPP) GetToolTrapAddress(_DrawPicture);
- SetToolTrapAddress((UniversalProcPtr) MyDrawPicture, _DrawPicture);
- oldInitWindows = (InitWindPP) GetToolTrapAddress(_InitWindows);
- SetToolTrapAddress((UniversalProcPtr) MyInitWindows, _InitWindows);
- // oldLaunch = (Ptr) GetToolTrapAddress(_Launch);
- // SetToolTrapAddress((UniversalProcPtr) MyLaunch, _Launch);
- }
- }
- RESETGLOB();
-
- return (*gp)(id);
- }
-
- pascal void MyDrawPicture(PicHandle pic, Rect* r)
- {
- DrawPictPP dp;
-
- SETGLOB();
- dp = (DrawPictPP) oldDrawPicture;
- RESETGLOB();
-
- (*dp)(pic, r);
-
- SETGLOB();
- if (!bypass && !isRunning)
- {
- GDHandle mainDev;
-
- mainDev = GetMainDevice();
-
- StartDraw(r, (**mainDev).gdPMap);
-
- isRunning = true;
- }
- RESETGLOB();
- }
-
- pascal void MyInitWindows(void)
- {
- InitWindPP iw;
-
- SETGLOB();
- iw = (InitWindPP) oldInitWindows;
-
- if (!bypass && doCleanup)
- {
- StopDraw();
- DoneDraw();
-
- bypass = true;
- }
- RESETGLOB();
-
- (*iw)();
- }
-
- static long* __GetCounter(void)
- {
- return (long*) "\0\0\0";
- }
-
- pascal void SETGLOB(void)
- {
- long* lp = __GetCounter();
-
- if (*lp == 0)
- SetUpA5();
-
- ++(*lp);
- }
-
- pascal void RESETGLOB(void)
- {
- long* lp = __GetCounter();
-
- --(*lp);
-
- if (*lp == 0)
- RestoreA5();
- }